﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BAL.EstRec
{
    public class CapFDVIndicadores
    {
        #region  properties

        Pos pos;
        int _tiempoImplementacion;
        int _visitasSugeridas;
        string _iniciativas;

        public Pos Pos
        {
            get { return pos; }
            set { pos = value; }
        }
        
        public int tiempoImplementacion
        {
            get { return _tiempoImplementacion; }
            set { _tiempoImplementacion = value; }
        }

        public int visitasSugeridas
        {
            get { return _visitasSugeridas; }
            set { _visitasSugeridas = value; }
        }

        public string iniciativas
        {
            get { return _iniciativas; }
            set { _iniciativas = value; }
        }

        #endregion

        public CapFDVIndicadores()
        { }

        public CapFDVIndicadores(Pos p)
        {
            this.pos = p;            
        }

        public CapFDVIndicadores(Pos p, int tiempoImplement, int visitasSug, string inic)
        {
            this.Pos = p;
            this.tiempoImplementacion = tiempoImplement;
            this.visitasSugeridas = visitasSug;
            this.iniciativas = inic;
        }

        public void Calculate(string idPos, CapturasPFDV oCPFDV)
        {
            // iniciativas
            int cnt = 0;
            string inic = "";

            foreach (CapturaPivotFDV item in oCPFDV.ObCollPFDV)
            {
                if(item.recurso.excReglaIniciativa)
                    cnt++;
            }

            if (cnt > 2)
                inic = "Excedidas";
            else inic = "OK";

            // Visitas sugeridas
            var v = from o in oCPFDV.ObCollPFDV
                    where o.pos.idPos == idPos
                    group o by o.recurso into g
                    select new { Recurso = g.Key, maxVal = g.Max(c => c.cantidad) };

            var y = (
                    from o in oCPFDV.ObCollPFDV
                    where o.pos.idPos == idPos
                    group o by o.pos into g
                    select new { Pos = g.Key, maxVal = g.Max(c => c.recurso.visitasSugeridas) }
                    ).Max(m  => m.maxVal);
             
            // tiempo implementación
            var x = (from o in oCPFDV.ObCollPFDV
                    where o.pos.idPos == idPos
                    group o by o.pos into g
                    select new { Pos = g.Key, sumVal = g.Sum(s => s.recurso.tiempoImplementacion * s.cantidad) }
                    ).Sum(s => s.sumVal);

            
        }//

    }//end class
}
